from django.db import models


# Create your models here.
# 模型字段类型
class UserModel(models.Model):
    # pass
    uid = models.AutoField(auto_created=True, primary_key=True, serialize=False)
    # CharField 字符串类型 unique=True 确保唯一性 db_index 索引
    name = models.CharField(max_length=30, unique=True, db_index=True)
    age = models.IntegerField(default=19)
    sex = models.BooleanField(default=True)
    info = models.TextField(null=True, blank=True)
    # max_digits 总位数 decimal_places 小数点后位数
    salary = models.DecimalField(max_digits=10, decimal_places=2, default=10000.01)
    # salary = models.FloatField(default=10000.01)
    # 日期
    birthday = models.DateField(default="2000-01-01")
    # 时间
    create_time0 = models.TimeField(auto_now=True)
    create_time1 = models.DateTimeField(auto_now_add=True)
    # 文件或图片

    file = models.FileField(upload_to="static/files", null=True, blank=True)
    image = models.ImageField(upload_to="static/icons", null=True, blank=True)

    # 其他约束
    choices = ((1, "青铜"), (2, "大师"), (3, "王者"))
    user_type1 = models.IntegerField(
        choices=choices, default=1, name="utype1", verbose_name="用户类型1"
    )
    user_type2 = models.IntegerField(
        choices=choices,
        default=1,
        editable=False,
        db_column="utype2",
        verbose_name="用户类型2",
    )
    # 增删改查


class PersonModel(models.Model):
    name = models.CharField(max_length=30, unique=True, db_index=True)
    age = models.IntegerField(default=19)

    class Meta:
        db_table = "tb_person"

    def __str__(self):
        return f"{self.name} - {self.age}"

    def __repr__(self):
        return f"{self.name} - {self.age}"


# ORM    ->   对象关系映射
# 模型类  ->   表结构
# 对象    ->   表的一条数据
# 类属性  ->  表的字段
